package at.fhj.itm11.antesk.memory.model;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;

/**
 * Defines one single field of the board.
 * 
 * @author Ivan Antes-Klobucar
 * @version 1.0
 *
 */
public class Field extends JButton implements ActionListener{
	
	private static final long serialVersionUID = -3339968755312505789L;
	private int id;
	private Images images;
	private ImageIcon img;
	private Logic logic;
	
	/**
	 * Default constructor for this class.
	 * 
	 * @param id Number on the field
	 */
	public Field(int id){
		this.id = id;
		this.images = new Images();
		this.img = images.getImg(id);
				
		logic = Logic.getInstance();
		addActionListener(this);
	}

	public int getId() {
		return id;
	}

	public ImageIcon getImg() {
		return img;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(logic.isEnabled())
			logic.validateEntry((Field) e.getSource());
	}
	
	public boolean equals(Field f){
		if(f.getId() == id)
			return true;
		
		return false;
	}
}
